﻿using System;
using System.ComponentModel;
using System.Data.SQLite;

namespace Theodorus
{
	class TheodorusModel : INotifyPropertyChanged
	{
		public string Filename
		{
			get
			{
				var bldr = new SQLiteConnectionStringBuilder(ConnectionString);
				return bldr.DataSource;
			}
		}

		public bool IsConnected
		{
			get
			{
				return !String.IsNullOrEmpty(ConnectionString);
			}
		}

		private string _connectionString;
		public string ConnectionString
		{
			get { return _connectionString; }
			set 
			{
				if (value != _connectionString)
				{
					_connectionString = value;
					OnPropertyChanged("ConnectionString");
					OnPropertyChanged("IsConnected");
					OnPropertyChanged("Filename");
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
		
		protected void OnPropertyChanged(string name)
		{
			var pceh = PropertyChanged;
			if (pceh != null)
			{
				pceh(this, new PropertyChangedEventArgs(name));
			}
		}
	}
}
